// 管理extension.list标签
var managerGit = Vue.component('managerGit', {
    template: readComponentHTML("managerGit"),
    data() {
        return {
            form: {
                title: ''
            },
            config: {
                userName: "",
                passWord: "",
                repositoryList: []
            },
            ruleForm: {
                gitUrl: '',
                branch: 'master',
                branchs:[],
                name: ''
            },
            dialogFormVisible: false,
            rules: {
                gitUrl: [
                    {required: true, message: '请输入仓库地址', trigger: 'blur'},
                ],
                branch: [
                    {required: true, message: '请输入仓库分支', trigger: 'blur'}
                ]
            }
        };
    },
    mounted() {
        this.init();
    },
    methods: {
        modify() {
            var that = this;
            that.openLoading();
            axios
                .post('/version/controll/config/update',
                    JSON.stringify(this.ruleForm),
                    {headers: {'Content-Type': 'application/json'}})
                .then(function (response) {
                    that.$message({
                        message: '修改成功',
                        type: 'success'
                    });
                    that.dialogFormVisible = false;
                    that.init();
                    that.closeLoading();
                })
                .catch(error => this.$message.error(JSON.stringify(error)));
        },
        handleEdit(index, row) {
            this.dialogFormVisible = true;
            this.ruleForm.branch = row.branch;
            this.ruleForm.gitUrl = row.gitUrl;
            this.ruleForm.name = row.name;
            var that = this;
            that.openLoading();
            axios
                .post('/version/controll/branchs/remote',
                    JSON.stringify(this.ruleForm),
                    {headers: {'Content-Type': 'application/json'}})
                .then(function (response) {
                    that.ruleForm.branchs = response.data;
                    that.closeLoading();
                })
                .catch(error => this.$message.error(JSON.stringify(error)));
        },
        handleDelete(index, row) {
            var that = this;
            that.openLoading();
            axios
                .get('/version/controll/config/del?name=' + row.name)
                .then(function (response) {
                    that.$message({
                        message: '删除成功',
                        type: 'success'
                    });
                    that.openLoading();
                    that.init();
                })
                .catch(error => this.$message.error(JSON.stringify(error)));
        },
        // 新增标签
        submitForm: function () {
            var that = this;
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    // if (this.ruleForm.path.indexOf(this.separator + "WEB-INF" + this.separator + "extensions" + this.separator + "extensions.list") == -1) {
                    //     this.ruleForm.path += this.separator + "WEB-INF" + this.separator + "extensions" + this.separator + "extensions.list";
                    // }
                    this.ruleForm.branch = "master";
                    that.openLoading();
                    axios
                        .post('/version/controll/config/add',
                        JSON.stringify(this.ruleForm),
                        {headers: {'Content-Type': 'application/json'}})
                        .then(function (response) {
                            that.init();
                            that.closeLoading();
                        })
                        .catch(error => this.$message.error(JSON.stringify(error)));
                } else {
                    that.$message.error('请完善必填信息');
                    return false;
                }
            });
        },
        // 重置
        resetForm: function () {
            this.$refs['ruleForm'].resetFields();
        },
        // 初始化 读取全局的标签集合
        init: function () {
            var that = this;
            that.openLoading();
            axios.get('/version/controll/config/load')
                .then(function (response) {
                    if (response.data) {
                        that.config = response.data;
                    }
                    that.closeLoading();
                });
        }
    }
})